var appServer = 'https://order.wz1996.wang/wzbg/media/sts';
var bucket = 'wangzheng1996';
var region = 'oss-cn-shanghai';
var urllib = OSS.urllib;
var Buffer = OSS.Buffer;
var endPoint = "https://oss-cn-shanghai.aliyuncs.com";
var OSS = OSS.Wrapper;
var STS = OSS.STS;
var applyTokenDo = function(func) {
	var url = appServer;
	return urllib.request(url, {
		method: 'GET',
		headers: {
			'token': localStorage.getItem("token")
		}
	}).then(function(result) {
		console.log('1111111111111111111')
		console.log(JSON.parse(result.data));
		var creds = JSON.parse(result.data).data.credentials;
		
		var client = new OSS({
			region: region,
			accessKeyId: creds.accessKeyId,
			accessKeySecret: creds.accessKeySecret,
			stsToken: creds.securityToken,
			endpoint:endPoint,
			bucket: bucket
		});
		return func(client);
	});
};
var uploadFile = function(client) {
	var file = document.getElementById('file').files[0];
	var key = "city/" + getRandom() + "." + file.name.split(".")[1];
	return client.multipartUpload(key, file, {}).then(function(res) {
		res.res.requestUrls[0] = res.res.requestUrls[0].indexOf('?') == -1?res.res.requestUrls[0]:res.res.requestUrls[0].split("?")[0];
		$("#imghidden").val(res.res.requestUrls[0])
	});
};